using IrisGenerator.Common.DataTypes;
using IrisGenerator.Common.Tools;
namespace IrisGenerator.Common.Modules
{


    public partial class Option
    {

        private System.Nullable<System.Guid> _optId;

        private System.Nullable<System.Guid> _modId;

        private System.Nullable<System.Guid> _forId;

        private System.Nullable<System.Guid> _valTypId;

        private string _optCode;

        private string _optDescription;

        private Formater _formater;

        private Module _module;

        private ValueType _valueType;

        private OptionInstanceCollection _optionInstanceCollection;

        public virtual System.Nullable<System.Guid> OptId
        {
            get
            {
                return _optId;
            }
            set
            {
                _optId = value;
            }
        }

        public virtual string OptCode
        {
            get
            {
                return _optCode;
            }
            set
            {
                _optCode = value;
            }
        }

        public virtual string OptDescription
        {
            get
            {
                return _optDescription;
            }
            set
            {
                _optDescription = value;
            }
        }

        public virtual Formater Formater
        {
            get
            {
                if ((this._formater == null))
                {
                    this._formater = Formater.Load(this._forId);
                }
                return this._formater;
            }
            set
            {
                _formater = value;
            }
        }

        public virtual Module Module
        {
            get
            {
                if ((this._module == null))
                {
                    this._module = Module.Load(this._modId);
                }
                return this._module;
            }
            set
            {
                _module = value;
            }
        }

        public virtual ValueType ValueType
        {
            get
            {
                if ((this._valueType == null))
                {
                    this._valueType = ValueType.Load(this._valTypId);
                }
                return this._valueType;
            }
            set
            {
                _valueType = value;
            }
        }

        public virtual OptionInstanceCollection OptionInstanceCollection
        {
            get
            {
                if ((this._optionInstanceCollection == null))
                {
                    _optionInstanceCollection = OptionInstance.Select_OPTION_INSTANCE_By_OPT_ID(this.OptId);
                }
                return this._optionInstanceCollection;
            }
        }

        private void Clean()
        {
            this.OptId = null;
            this._modId = null;
            this._forId = null;
            this._valTypId = null;
            this.OptCode = string.Empty;
            this.OptDescription = string.Empty;
            this.Formater = null;
            this.Module = null;
            this.ValueType = null;
            this._optionInstanceCollection = null;
        }

        private void Fill(System.Data.DataRow dr)
        {
            this.Clean();
            if ((dr["OPT_ID"] != System.DBNull.Value))
            {
                this.OptId = ((System.Nullable<System.Guid>)(dr["OPT_ID"]));
            }
            if ((dr["MOD_ID"] != System.DBNull.Value))
            {
                this._modId = ((System.Nullable<System.Guid>)(dr["MOD_ID"]));
            }
            if ((dr["FOR_ID"] != System.DBNull.Value))
            {
                this._forId = ((System.Nullable<System.Guid>)(dr["FOR_ID"]));
            }
            if ((dr["VAL_TYP_ID"] != System.DBNull.Value))
            {
                this._valTypId = ((System.Nullable<System.Guid>)(dr["VAL_TYP_ID"]));
            }
            if ((dr["OPT_CODE"] != System.DBNull.Value))
            {
                this.OptCode = ((string)(dr["OPT_CODE"]));
            }
            if ((dr["OPT_DESCRIPTION"] != System.DBNull.Value))
            {
                this.OptDescription = ((string)(dr["OPT_DESCRIPTION"]));
            }
        }

        public static OptionCollection Select_OPTION_By_FOR_ID(System.Nullable<System.Guid> FOR_ID)
        {
            IrisGenerator.Dal.Option dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Option();
                System.Data.DataSet ds = dbo.Select_OPTION_By_FOR_ID(FOR_ID);
                OptionCollection collection = new OptionCollection();
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1))
                    {
                        Option obj = new Option();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null))
                        {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public static OptionCollection Select_OPTION_By_MOD_ID(System.Nullable<System.Guid> MOD_ID)
        {
            IrisGenerator.Dal.Option dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Option();
                System.Data.DataSet ds = dbo.Select_OPTION_By_MOD_ID(MOD_ID);
                OptionCollection collection = new OptionCollection();
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1))
                    {
                        Option obj = new Option();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null))
                        {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public static OptionCollection Select_OPTION_By_VAL_TYP_ID(System.Nullable<System.Guid> VAL_TYP_ID)
        {
            IrisGenerator.Dal.Option dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Option();
                System.Data.DataSet ds = dbo.Select_OPTION_By_VAL_TYP_ID(VAL_TYP_ID);
                OptionCollection collection = new OptionCollection();
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1))
                    {
                        Option obj = new Option();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null))
                        {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public static OptionCollection GetAll()
        {
            IrisGenerator.Dal.Option dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Option();
                System.Data.DataSet ds = dbo.OPTION_Select_All();
                OptionCollection collection = new OptionCollection();
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1))
                    {
                        Option obj = new Option();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null))
                        {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public static Option Load(System.Nullable<System.Guid> OPT_ID)
        {
            IrisGenerator.Dal.Option dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Option();
                System.Data.DataSet ds = dbo.OPTION_Select_One(OPT_ID);
                Option obj = null;
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    if ((ds.Tables[0].Rows.Count > 0))
                    {
                        obj = new Option();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Load()
        {
            IrisGenerator.Dal.Option dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Option();
                System.Data.DataSet ds = dbo.OPTION_Select_One(this.OptId);
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    if ((ds.Tables[0].Rows.Count > 0))
                    {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Insert()
        {
            IrisGenerator.Dal.Option dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Option();
                dbo.OPTION_Insert(this._modId, this._forId, this._valTypId, this.OptCode, this.OptDescription);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Delete()
        {
            IrisGenerator.Dal.Option dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Option();
                dbo.OPTION_Delete(this.OptId);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Update()
        {
            IrisGenerator.Dal.Option dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.Option();
                dbo.OPTION_Update(this.OptId, this._modId, this._forId, this._valTypId, this.OptCode, this.OptDescription);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }
    }
}
